/*
 * @Author: your name
 * @Date: 2021-04-27 16:07:16
 * @LastEditTime: 2021-04-27 17:55:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \js_study\demo04\js\index.js
 */

var _obj = {};

// defineProperty
Object.defineProperty(_obj,"method",{
    get(){
        return "获取：" + method;
    },
    set(newval){
        method = newval;
        console.log("设置：" + newval);
    }
})

// defineProperties
Object.defineProperties(_obj,{
    pername:{
        get(){
            return "获取方法：" + pername;
        },
        set(newval){
            pername = newval;
            console.log("设置方法：" + newval);
        } 
    },
})

// Proxy 
const man = {
    name: '王五'
};

let manper = new Proxy(man,{
    get(man,prop){
        console.log("读取");
        return man[prop]
    },
    set(man,prop,val){
        console.log("设置");
        man[prop] = val;
    }
})

manper.name = "夏六";
console.log(man);


_obj.pername = "张三";
_obj.method = "加法";